import axios, { AxiosRequestHeaders } from 'axios'

/**
 * 创建请求
 * @param axiosConfig - axios配置，后续可继续优化
 */
export function createRequest(axiosConfig: any) {
  const instance = axios.create(axiosConfig)
  instance.interceptors.request.use(
    (config) => {
      ;(config.headers as AxiosRequestHeaders).SERVICE_TOKEN = 'web_dp'
      ;(config.headers as AxiosRequestHeaders).USER_TOKEN = sessionStorage.getItem('token') || 'app'
      ;(config.headers as AxiosRequestHeaders).zzzd = '5'
      return config
    },
    (error) => {
      return Promise.reject(error)
    }
  )
  instance.interceptors.response.use(
    (response) => {
      const res = response.data
      return res
    },
    (error) => {
      // window.$notification?.error({
      //   content: '错误',
      //   meta: error?.response?.data?.data,
      //   duration: 3000,
      // })
      return Promise.reject(error)
    }
  )
  return instance
}
